<template>
  <div id="AsnDetailList">
    <v-tableTitle
      :btnConfig="btnConfig"
      :tableSelectData="selectData"
      @backList="backList"
      @btnTableData="btnTableData"
      @save="save"
      @del="del"
      @newCreate="newCreate"
      @saveDeatails="saveDeatails"
      @back="back"
      :importVisualType="$t('in.receiptDetails1')"
      :totalCount="totalCount"
      :importStatus="importStatus"
      :failedCount="failedCount"
      :successCount="successCount"
      :beforeNumber="beforeNumber"
      :afterNumber="afterNumber"
      :importVisualDialogFlag="importVisualDialogFlag"
      @handleDownErrorFile="exceptionFileUrl"
      @downloadExcelFile="downloadExcelFile"
      @exportASNDetails="exportASNDetails"
    ></v-tableTitle>
    <div class="detail">
      <v-navMenu
        :detailNav="detailNav"
        :menuData="menuData"
        @setMentActive="setMentActive"
        v-if="detailNav != 1"
      >
      </v-navMenu>
      <component
        :data="{ detailData, argument }"
        :is="currentComponent"
      ></component>
    </div>
  </div>
</template>

<script>
import tableTitle from "commons/TableTitle";
import detail from "commons/Detail";
import table from "commons/Table";
import navMenu from "commons/NavMenu";
import baseMixin from "@/mixins/BaseMixin";
import config from "../Config";
import bus from "../../../../../bus/bus";
import * as XLSX from "xlsx/xlsx.mjs";

export default {
  name: "DetailList",
  mixins: [baseMixin, config],
  data() {
    return {
      newFlag: false,
      mainFlag: false,
      detailFlag: false,
      // 导入可视化 start
      importVisualDialogFlag: false,
      totalCount: 0,
      importStatus: 0,
      failedCount: 0,
      successCount: 0,
      beforeNumber: 0,
      afterNumber: 0,
      exceptionUrl: undefined,
      // 库区信息
      importType: 10315,
      importSeriType: 10318,
      // 导入可视化 end
      argument: {},
      detailData: {},
      selectData: [],
      menuData: [
        { label: this.$t("in.asnDetail"), index: "2" },
        { label: this.$t("config.batchProp"), index: "3" },
        { label: this.$t("in.UdfDetails"), index: "4" },
        { label: this.$t("in.QcDetails"), index: "5" },
        { label: this.$t("config.supplier"), index: "6" },
        { label: this.$t("in.SalesReturn"), index: "7" },
        { label: this.$t("in.LpnDetails"), index: "8" },
        { label: this.$t("in.serialNumberInfo"), index: "9" },
      ],
      detailNav: "1",
      componentConfig: [
        {
          name: "Table",
          label: "table",
          component: () => import("./page/Table.vue"),
        },
        {
          name: "AsnDetails",
          label: this.$t("in.asnDetail"),
          component: () => import("./page/AsnDetails.vue"),
        },
        {
          name: "LotTableDetails",
          label: this.$t("config.batchProp"),
          component: () => import("./page/LotTableDetails.vue"),
        },
        {
          name: "UdfDetails",
          label: this.$t("in.UdfDetails"),
          component: () => import("./page/UdfDetails.vue"),
        },
        {
          name: "QcDetails",
          label: this.$t("in.QcDetails"),
          component: () => import("./page/QcDetails.vue"),
        },
        {
          name: "SupplierDetails",
          label: this.$t("config.supplier"),
          component: () => import("./page/SupplierDetails.vue"),
        },
        {
          name: "SalesReturn",
          label: this.$t("in.SalesReturn"),
          component: () => import("./page/SalesReturn.vue"),
        },
        {
          name: "LpnDetails",
          label: this.$t("in.LpnDetails"),
          component: () => import("./page/LpnDetails.vue"),
        },
        {
          name: "SerialNumberInformationList",
          label: "SerialNumberInformationList",
          component: () => import("./page/InSerialNumberInformationList.vue"),
        },
      ],
      lookUrl: "/queryQtybySku/",
    };
  },
  computed: {
    btnConfig() {
      if (this.detailNav == 1) {
        return [
          {
            label: this.$t("common.create"),
            certigier:
              this.newDetailStatus ||
              !this.btnPermNameList.includes("WM010125"),
            invalid: "newCreate",
          },
          /*{
            label: this.$t('common.save'),
            certigier: this.newDetailStatus,
            invalid: "save",
          },*/
          {
            label: this.$t("common.delete"),
            certigier:
              this.deleteDetailStatus ||
              !this.btnPermNameList.includes("WM010126"),
            disabled: true,
            invalid: "del",
          },
          {
            type: "table",
            certigier:
              this.newDetailStatus ||
              !this.btnPermNameList.includes("WM010127"),
            label: this.$t("in.checkPoDetail"),
            invalid: "po",
            tableConfig: [
              {
                label: this.$t("in.receiptkey"),
                prop: "receiptkey",
                input: "input",
                disabled: false,
              },
              {
                label: this.$t("config.shipper"),
                prop: "storerkey",
                input: "input",
                disabled: false,
              },
              {
                label: this.$t("config.sku"),
                prop: "sku",
                input: "input",
                disabled: false,
              },
              {
                label: this.$t("in.totalqtyexpected"),
                prop: "qtyexpected",
                input: "input",
                disabled: false,
              },
              {
                label: this.$t("in.qtyreceived"),
                prop: "qtyreceived",
                input: "input",
                disabled: false,
              },
            ],
            url: "queryQtybySku/",
          },
          {
            type: "file",
            certigier:
              this.uploadStatus || !this.btnPermNameList.includes("WM010129"),
            label: this.$t("in.importReceivedDetail"),
            invalid: "file",
            importType: "10315",
            importUrl: "importASNDetails",
            downTemplate: "exportASNDetails",
            title:this.$t('transmit.importtypeASNDetail')
          },
          {
            type: "file",
            certigier:
              this.uploadStatus || !this.btnPermNameList.includes("WM010135"),
            label: this.$t("in.importReceivedSeriDetail"),
            invalid: "file",
            importType: "10318",
            importUrl: "importSerinumASNDetails",
            downTemplate: "downloadExcelFile",
            title:this.$t('other.receivedSerinum')
          },
        ];
      } else if (this.newFlag) {
        return [
          {
            label: this.$t("app.saveDetail"),
            certigier: !this.btnPermNameList.includes("WM010130"),
            invalid: "saveDeatails",
          },
          {
            label: this.$t("common.return"),
            certigier: !this.btnPermNameList.includes("WM010131"),
            invalid: "back",
          },
        ];
      } else {
        return [
          {
            label: this.$t("common.create"),
            certigier:
              this.newDetailStatus ||
              !this.btnPermNameList.includes("WM010125"),
            invalid: "newCreate",
          },
          {
            label: this.$t("common.delete"),
            certigier:
              this.deleteDetailStatus ||
              !this.btnPermNameList.includes("WM010126"),
            disabled: true,
            invalid: "del",
          },
          {
            label: this.$t("common.return"),
            certigier: !this.btnPermNameList.includes("WM010131"),
            invalid: "backList",
          },
        ];
      }
    },
    currentComponent() {
      return this.componentConfig[this.detailNav - 1].component;
    },
  },
  methods: {
    initialize() {
      this.totalCount = 0;
      this.importStatus = 0;
      this.failedCount = 0;
      this.successCount = 0;
      this.beforeNumber = 0;
      this.afterNumber = 0;
      this.exceptionUrl = undefined;
    },
    importVisualBeforeClose() {
      console.log("importVisualBeforeClose = %o", 1);
      this.importVisualDialogFlag = false;
      this.initialize();
    },
    exceptionFileUrl(exceptionUrl, importType) {
      console.log(exceptionUrl, importType);
      const data = [
        {
          exceptionFileUrl: exceptionUrl,
        },
      ];
      let exceptionFileName = "收货明细导入模板异常文件.xls";
      if (importType == 10315) {
        exceptionFileName = "收货明细导入模板异常文件.xls";
      } else if (importType == 10318) {
        exceptionFileName = "ASN收货单序列号导入收货模板异常文件.xls";
      }
      // 异常下载配置
      let urlConf = { responseType: "blob" };
      let url = "/comExcelImportResult/downloadExceptionFile";
      let options = {
        type:
          "application/vnd.openxmlformats-officedocument.wordprocessingml.document;charset=utf-8",
      };

      try {
        this.$api.post(url, data, urlConf).then((res) => {
          let blobParts = [res.data];
          if (window.navigator.msSaveBlob) {
            const blobObject = new Blob(blobParts);
            window.navigator.msSaveBlob(blobObject, exceptionFileName);
          } else {
            let tagName = "a";
            const blob = new Blob(blobParts, options);
            const downloadElement = document.createElement(tagName);
            // 创建下载的链接
            const href = window.URL.createObjectURL(blob);
            downloadElement.style.display = "none";
            downloadElement.href = href;
            // 下载后文件名
            downloadElement.download = exceptionFileName;
            document.body.appendChild(downloadElement);
            // 点击下载
            downloadElement.click();
            // 下载完成移除元素
            document.body.removeChild(downloadElement);
            // 释放掉blob对象
            window.URL.revokeObjectURL(href);
          }
          this.importVisualDialogFlag = false;
          this.initialize();
        });
      } catch (e) {
        this.$message.error(e);
      } finally {
        
      }
    },
    //导出
    async exportASNDetails(data) {
      this.argument = {receiptkey:this.$parent.$refs.detail.detailData.receiptkey}

      try {
        let xls = "收货明细导入模板.xls";
        let res = await this.$api.post(
          `/exportASNDetails/${this.argument.receiptkey}/` + xls,
          data,
          { responseType: "blob" }
        );
        if (window.navigator.msSaveBlob) {
          var blobObject = new Blob([res.data]);
          window.navigator.msSaveBlob(
            blobObject,
            "收货明细导入模板-" + this.argument.receiptkey + ".xls"
          );
        } else {
          var blob = new Blob([res.data], {
            type:
              "application/vnd.openxmlformats-officedocument.wordprocessingml.document;charset=utf-8",
          });
          var filename =
            "收货明细导入模板-" + this.argument.receiptkey + ".xls";
          var downloadElement = document.createElement("a");
          var href = window.URL.createObjectURL(blob); //创建下载的链接
          downloadElement.style.display = "none";
          downloadElement.href = href;
          downloadElement.download = filename; //下载后文件名
          document.body.appendChild(downloadElement);
          downloadElement.click(); //点击下载
          document.body.removeChild(downloadElement); //下载完成移除元素
          window.URL.revokeObjectURL(href); //释放掉blob对象
        }
      } catch (e) {
        this.$message.error(e);
      }
    },
    async downloadExcelFile(data) {
      try {
        let xlsName = "ASN收货单序列号导入收货模板.xls";
        let url = "/downloadExcelFile/" + xlsName;
        let res = await this.$api.post(url, data, { responseType: "blob" });
        if (window.navigator.msSaveBlob) {
          var blobObject = new Blob([res.data]);
          window.navigator.msSaveBlob(blobObject, xlsName);
        } else {
          var blob = new Blob([res.data], {
            type:
              "application/vnd.openxmlformats-officedocument.wordprocessingml.document;charset=utf-8",
          });
          var downloadElement = document.createElement("a");
          var href = window.URL.createObjectURL(blob); //创建下载的链接
          downloadElement.style.display = "none";
          downloadElement.href = href;
          downloadElement.download = xlsName; //下载后文件名
          document.body.appendChild(downloadElement);
          downloadElement.click(); //点击下载
          document.body.removeChild(downloadElement); //下载完成移除元素
          window.URL.revokeObjectURL(href); //释放掉blob对象
        }
      } catch (e) {
        this.$message.error(e);
      } finally {
        if (data.length !== 0) {
          
        }
      }
    },
    async upFile(data) {
      // 调用导入页面 = start /////////////////////////////
      this.importVisualDialogFlag = true;
      // 调用导入页面 =  end //////////////////////////////

      let file = data.get("file");
      console.log("file = %o", file);
      if (!file) {
        console.log("文件打开失败");
        this.$message.error(this.$t("msg.msg17"));
        return;
      } else {
        let re = await this.$api.post(
          `/sysExcelImportRule/selectExcelImportDefineByRuleImportDataType/${this.importType}`,
          {}
        );
        // 第几行开始读 excel解析成json需要key值 故从前一行开始读
        let range = re.data.data.readLineNum - 1;
        let sheets = re.data.data.templateSheetType;
        let result = await this.excelParsing(file, range);
        console.log("excelParsing = %o", result);

        // 调用导入页面 = start /////////////////////////////
        this.totalCount = result.length;
        this.importStatus = 1;
        // 调用导入页面 =  end //////////////////////////////

        let res;
        let num = 0;
        let arrayData = new Array();
        let excelImportSize = 10;
        // const key1 = crypto.randomUUID();
        const key = this.uuid();
        console.log("uuid = %o", key);

        for (const item of result) {
          const index = result.indexOf(item);
          num = index + 1;
          let i = num % excelImportSize;
          arrayData[i] = item;
          if (num % excelImportSize == 0 || num == result.length) {
            // data.append('arrayData', JSON.stringify(arrayData));  FormData
            data.set("arrayData", JSON.stringify(arrayData));
            data.set("total", result.length);

            // 调用导入页面 = start /////////////////////////////
            // 验证无效null元素
            let i = 0;
            arrayData.forEach((item) => {
              if (item !== null) {
                i += 1;
              }
            });
            this.beforeNumber = result.length - (i + this.afterNumber);
            this.afterNumber += i;
            // 调用导入页面 =  end //////////////////////////////

            // 当数量满一次导入数量时 或数量等于导入的数量时 发送给后端
            res = await this.$api.post(
              `/importASNDetails/${this.importType}/${key}`,
              data
            );
            // 清空传入的数据
            arrayData = new Array();
          }
        }
        let resData = res.data.data;
        console.log("返回结果:" + res);
        if (resData !== undefined && resData !== null) {
            // 调用导入页面 = start /////////////////////////////
            let failedCount = resData.value.failedCount;
            let successCount = resData.value.successCount;
            let exceptionFileUrl = resData.value.exceptionFileUrl;
            if (failedCount !== 0) {
              this.failedCount = failedCount;
              this.exceptionUrl = exceptionFileUrl;
              this.successCount = successCount;
              this.importStatus = 3;
            } else {
              this.importStatus = 2;
              this.successCount = successCount;
            }
            bus.$emit("asn.DetailList.Table.getTableData", {});
            // 调用导入页面 =  end //////////////////////////////

            // this.$message.success("this.$t('app.importMes')");
          } else {
            if (num === this.totalCount) {
              this.$message.error(resData.desc);
              this.importVisualBeforeClose();
            }
          }
      }
    },
    async upSeriFile(data) {
      // 调用导入页面 = start /////////////////////////////
      this.importVisualDialogFlag = true;
      // 调用导入页面 =  end //////////////////////////////

      let file = data.get("file");
      console.log("file = %o", file);
      if (!file) {
        console.log("文件打开失败");
        this.$message.error(this.$t("msg.msg17"));
        return;
      } else {
        let re = await this.$api.post(
          `/sysExcelImportRule/selectExcelImportDefineByRuleImportDataType/${this.importSeriType}`,
          {}
        );
        // 第几行开始读 excel解析成json需要key值 故从前一行开始读
        let range = re.data.data.readLineNum - 1;
        let sheets = re.data.data.templateSheetType;
        let result = await this.excelParsing(file, range);
        console.log("excelParsing = %o", result);

        // 调用导入页面 = start /////////////////////////////
        this.totalCount = result.length;
        this.importStatus = 1;
        // 调用导入页面 =  end //////////////////////////////

        let res;
        let num = 0;
        let arrayData = new Array();
        let excelImportSize = 10;
        // const key1 = crypto.randomUUID();
        const key = this.uuid();
        console.log("uuid = %o", key);

        for (const item of result) {
          const index = result.indexOf(item);
          num = index + 1;
          let i = num % excelImportSize;
          arrayData[i] = item;
          if (num % excelImportSize == 0 || num == result.length) {
            // data.append('arrayData', JSON.stringify(arrayData));  FormData
            data.set("arrayData", JSON.stringify(arrayData));
            data.set("total", result.length);

            // 调用导入页面 = start /////////////////////////////
            // 验证无效null元素
            let i = 0;
            arrayData.forEach((item) => {
              if (item !== null) {
                i += 1;
              }
            });
            this.beforeNumber = result.length - (i + this.afterNumber);
            this.afterNumber += i;
            // 调用导入页面 =  end //////////////////////////////

            // 当数量满一次导入数量时 或数量等于导入的数量时 发送给后端
            res = await this.$api.post(
              `/importSerinumASNDetails/${this.importSeriType}/${key}`,
              data
            );
            // 清空传入的数据
            arrayData = new Array();
          }
        }
        let resData = res.data.data;
        console.log("返回结果:" + res);
        if (resData !== undefined && resData !== null) {
            // 调用导入页面 = start /////////////////////////////
            let failedCount = resData.value.failedCount;
            let successCount = resData.value.successCount;
            let exceptionFileUrl = resData.value.exceptionFileUrl;
            if (failedCount !== 0) {
              this.failedCount = failedCount;
              this.exceptionUrl = exceptionFileUrl;
              this.successCount = successCount;
              this.importStatus = 3;
            } else {
              this.importStatus = 2;
              this.successCount = successCount;
            }
            bus.$emit("asn.DetailList.Table.getTableData", {});
            // 调用导入页面 =  end //////////////////////////////

            // this.$message.success("this.$t('app.importMes')");
          } else {
            if (num === this.totalCount) {
              this.$message.error(resData.desc);
              this.importVisualBeforeClose();
            }
          }
        console.log(res);
      }
    },
    readFile(file) {
      //文件读取
      return new Promise((resolve) => {
        let reader = new FileReader();
        reader.readAsBinaryString(file); //以二进制的方式读取
        reader.onload = (ev) => {
          resolve(ev.target.result);
        };
      });
    },
    // 解析excel
    async excelParsing(file, range) {
      let data = await this.readFile(file);
      // 解析二进制格式数据
      let workbook = XLSX.read(data, { type: "binary" });
      //  获取第一个Sheet
      let worksheet = workbook.Sheets[workbook.SheetNames[0]];
      // 读取文件内容，（第一个sheet里的内容）
      // range：设置从第几行开始读取内容 ; defval 为空时显示列值为空
      // json数据格式
      let result = XLSX.utils.sheet_to_json(worksheet, {
        range: range,
        defval: "",
      });
      // 最终解析的 json 格式数据:'
      return result;
    },
    uuid(len, radix) {
      var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(
        ""
      );
      var uuid = [],
        i;
      radix = radix || chars.length;

      if (len) {
        // Compact form
        for (i = 0; i < len; i++) uuid[i] = chars[0 | (Math.random() * radix)];
      } else {
        // rfc4122, version 4 form
        var r;

        // rfc4122 requires these characters
        uuid[8] = uuid[13] = uuid[18] = uuid[23] = "-";
        uuid[14] = "4";

        // Fill in random data.  At i==19 set the high bits of clock sequence as
        // per rfc4122, sec. 4.1.5
        for (i = 0; i < 36; i++) {
          if (!uuid[i]) {
            r = 0 | (Math.random() * 16);
            uuid[i] = chars[i == 19 ? (r & 0x3) | 0x8 : r];
          }
        }
      }
      return uuid.join("");
    },

    //保存选中的数据
    async save() {
      if (this.selectData.length != 1) {
        this.$message.error(this.$t("msg.msg32"));
        return;
      }
      //   try {
      //     let res = await this.$api.post("/asn", this.selectData[0]);
      //     
      //       this.$message.success(res.returnMgr);
      //       if (this.flag) {
      //         this.cancel();
      //       } else {
      //         this.$refs.detailList.detailNav = "1";
      //       }
      //     } else {
      //       this.$message.error(res.returnMgr);
      //     }
      //   } catch (e) {
      //     this.$message.error(e);
      //   }
    },
    //删除数据
    del(data) {
      this.argument = {receiptkey:this.$parent.$refs.detail.detailData.receiptkey}

      data.forEach(async (item, index) => {
        try {
          let res = await this.$api.delete(
            `/asn/detail/${this.argument.receiptkey}/${item.receiptlinenumber}`
          );
          
            this.$message.success(res.returnMgr);
            this.$children[1].getTableData(1, {});
        } catch (e) {
          this.$message.error(e);
        } finally {
          this.$children[1].$refs.table.delSelectData(item, index);
        }
      });
    },
    //选中的数据
    setSelectData(data) {
      this.selectData = data;
    },
    //进入详情
    async setdialog(data) {
      this.argument = {receiptkey:this.$parent.$refs.detail.detailData.receiptkey}

      try {
        let res = await this.$api.get(
          `/asn/detail/detailed/${this.argument.receiptkey}/${data.receiptlinenumber}`
        );
        
          this.detailData = res.bean;
          this.detailNav = "2";
      } catch (e) {
        this.$message.error(e);
      }
    },
    //返回试图
    backList() {
      this.detailNav = "1";
    },
    //新建
    async newCreate() {
      for (let i in this.detailData) {
        this.detailData[i] = "";
      }
      this.detailData = {
        storerkey: "",
        packkey: "",
        qtyexpected: "0",
        sku: "",
        uom: "EA",
        grosswgt: "0",
        netwgt: "0",
        status: "0",
        qtyreceived: "0",
        toloc: "STAGE",
        tarewgt: "0",
        qcrequired: "0",
        qcautoadjust: "0",
        qcqtyinspected: "0",
        qcstatus: "N",
      };
      this.argument = {receiptkey:this.$parent.$refs.detail.detailData.receiptkey}

      try {
        let res = await this.$api.get(
          `/asn/detail/LineNumber/${this.argument.receiptkey}`
        );
        
          this.detailData.receiptlinenumber = res.bean;
          this.detailNav = "2";
        
      } catch (e) {
        this.$message.error(e);
      }
    },
    //导航值
    setMentActive(key) {
      this.detailNav = key;
    },
    async btnTableData(page, date, callback, searchData) {
      this.argument = {receiptkey:this.$parent.$refs.detail.detailData.receiptkey}

      let url = this.lookUrl + this.argument.receiptkey + "/";
      try {
        let res = await this.$api.post(`${url}${page}`, searchData);
        callback(res);
      } catch (e) {
        this.$message.error(e);
      }
    },
    //保存明细
    async saveDeatails() {
      this.$parent.$refs["detail"].$children[1].$refs.input.$refs[
        "from"
      ].validate((valid) => {
        if (valid) {
          this.mainFlag = true;
          this.$children[2].$refs.input.$refs["from"].validate((valid) => {
            if (valid) {
              this.detailFlag = true;
              if (this.detailFlag && this.mainFlag) {
                //上下数据均已校准 可以开始保存
                let detail = this.$parent.$children[1].detailData;
                let detailList = this.detailData;
                let data = {
                  ...detail,
                  receiptdetail: [{ ...detailList }],
                };
                try {
                  this.$api.post("/asn", data).then((res) => {
                    
                      this.$message.success(res.returnMgr);
                      let str = "";
                      this.argument = {receiptkey:this.$parent.$refs.detail.detailData.receiptkey}
                      // 查询现在的编号
                      this.$api
                        .get(
                          `/asn/detail/LineNumber/${this.argument.receiptkey}`
                        )
                        .then((res1) => {
                            str = res1.data.bean;
                            // 回归第一页 且清空其他页面的所有数据
                            this.detailData = {
                              receiptlinenumber: str,
                              packkey: "",
                              qtyexpected: "0",
                              uom: "EA",
                              sku: "",
                              grosswgt: "0",
                              netwgt: "0",
                              status: "0",
                              qtyreceived: "0",
                              toloc: "STAGE",
                              tarewgt: "0",
                              qcrequired: "0",
                              qcautoadjust: "0",
                              qcqtyinspected: "0",
                              qcstatus: "N",
                              storerkey: data.storerkey,
                            };
                            this.detailNav = "2";
                          }
                        );
                  });
                } catch (e) {
                  this.$message.error(e);
                }
              }
            }
          });
        }
      });
    },
    // 返回到列表页面
    back() {
      this.$router.push({ name: "asn" });
    },
  },
  mounted() {
    // this.newFlag = this.$store.state.newFlag;

    // if (Object.keys(this.$store.state.skip).length !== 0) {
    //   let data = this.$store.state.skip;
    //   this.argument = data.routeData;
    //   this.detailData = data.detailList;
    //   this.detailNav = data.detailListNav;
    // } else if (this.newFlag) {
    //   this.argument = {
    //     receiptkey: this.$store.state.routeId,
    //   };
    //   for (let i in this.detailData) {
    //     this.detailData[i] = "";
    //   }
    //   this.detailData = {
    //     receiptlinenumber: "00001",
    //     packkey: "",
    //     qtyexpected: "0",
    //     uom: "EA",
    //     sku: "",
    //     grosswgt: "0",
    //     netwgt: "0",
    //     status: "0",
    //     qtyreceived: "0",
    //     toloc: "STAGE",
    //     tarewgt: "0",
    //     qcrequired: "0",
    //     qcautoadjust: "0",
    //     qcqtyinspected: "0",
    //     qcstatus: "N",
    //     storerkey: "",
    //   };
    //   this.detailNav = "2";
    // } else {
    //   this.argument = this.$store.state.routeData;
    // }
    const query = this.$route.query;
    if(query.newFlag){
      this.newFlag = true;
      this.detailData = {
        receiptlinenumber: "00001",
        packkey: "",
        qtyexpected: "0",
        uom: "EA",
        sku: "",
        grosswgt: "0",
        netwgt: "0",
        status: "0",
        qtyreceived: "0",
        toloc: "STAGE",
        tarewgt: "0",
        qcrequired: "0",
        qcautoadjust: "0",
        qcqtyinspected: "0",
        qcstatus: "N",
        storerkey: "",
      };
      this.detailNav = "2";
    }else{
      this.argument = query;
    }
  },
  components: {
    "v-tableTitle": tableTitle,
    "v-table": table,
    "v-detail": detail,
    "v-navMenu": navMenu,
  },
  watch: {
    detailNav: {
      handler(data) {
        if (data !== "1") {
          this.$store.commit("setTemporary", true);
        } else {
          this.$store.commit("setTemporary", "");
        }
      },
      immediate: true,
      deep: true,
    },
    selectData(data) {
      if (this.permissionStatus) {
        if (data.length > 0) {
          this.deleteDetailStatus = false;
        } else {
          this.deleteDetailStatus = true;
        }
      }
    },
  },
};
</script>

<style></style>
